package com.example.boot01.Controller;

import com.example.boot01.entity.Person;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class ParamController {
    @RequestMapping("/p1")
    @ResponseBody
    public String p1(HttpServletRequest request) {
        String name = request.getParameter("name");
        String age = request.getParameter("age");
        return "接受到参数:" + name + "age=" + age;
    }

    @RequestMapping("/p2")
    @ResponseBody
    public String p2(String name, int age) {
        return "接受到参数:" + name + "age=" + age;
    }

    @RequestMapping("/p3")
    @ResponseBody
    public String p3(Person person) {
        /* 当声明的参数是一个自定义对象时;SpringMVC框架会
         会通过搭设机制的到对象的参数名称,然后查找是否含有传递过来的同名参数
         如果包含则会调用set方法吧接受过来的参数赋值给person对象
         */
        return person.toString();
    }
}
